<?php

namespace App\Http\Controllers;


use Illuminate\Http\Request;

use Illuminate\Support\Facades\Mail;

use Illuminate\Support\Facades\Redis;

class IndexController extends Controller
{

    private  $request;
    public function __construct(Request $request)
    {
        //
        $this->request = $request;
        parent::__construct($request);
    }

    /**
     * redis demo
     */
    public function index()
    {

        // redis test
        $redis = Redis::connection('share_3');
//        $status = $redis->set('name','葛有文');

//        $redis->expire('name', 100);
//        var_dump($status);
        //队列
        $redis->rpush('MQ', time());
//        echo $redis->lpop('MQ');
//        print_r(unserialize($redis->lpop('MQ')));
        exit;
    }

    /**
     * email demo
     * @return \Illuminate\Http\JsonResponse
     */
    public function mail()
    {
        date_default_timezone_set('PRC');
        $user = [
            'email' => '707250043@qq.com',
//            'email' => '690591423@qq.com',
        ];
        try
        {
            Mail::send('mails.welcome', ['key' => 'value111'], function($mail) use($user)
            {
                $mail->to($user['email'])->subject('点餐提醒!');
            });
        } catch(\Exception $e)
        {
            return response()->json([$e->getMessage()]);
        }
        return response()->json(['ok']);
    }


    public function sendMsg()
    {
        $mobile = [
            '18055232662'
//            '13955198874'
        ];
        $mobile = is_array($mobile) ? $mobile : [$mobile];
        include base_path().'/vendor/alidayu/TopSdk.php';
        $c = new \TopClient();
        $c ->appkey = '23424244' ;
        $c ->secretKey = 'fc04dbdcf77151fd5f76f0884b4fe237' ;
        $req = new \AlibabaAliqinFcSmsNumSendRequest;
        foreach($mobile as $val){
            $req ->setExtend( "" );
            $req ->setSmsType( "normal" );
            $req ->setSmsFreeSignName( "点餐提醒" );
            $req ->setSmsParam( "" );
            $req ->setRecNum( $val );
            $req ->setSmsTemplateCode( "SMS_69175549" );
        }
;
        $res = $c ->execute( $req );
        print_r($res);
    }

}
